<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
    /**
    * @param {number[]} prices
    * @return {number}
    */
    var maxProfit = function(ary) {
        if(ary.length<=1)
        {
            return 0;
        }
        var ans=[];
        ans[0]=0;
        for(var i=1;i<ary.length;i++)
        {
           ans[i]=ans[i-1]+Math.max(ary[i]-ary[i-1],0);
        //    console.log(ary[i]-ary[i-1],ans[i]);
        }
        // console.log(ans[ary.length-1]);
        return ans[ary.length-1];
    };
    var a= [7,6,4,3,1];
    maxProfit(a);
    </script>
</body>
</html>